//
//  ModelInsurance.m
//  MemberProject
//
//  Created by vincent luo on 15/7/14.
//  Copyright (c) 2015年 MAC OS X. All rights reserved.
//

#import "ModelInsurance.h"

@implementation ModelInsurance
+(ModelInsurance *)getInsuranceForDic:(NSDictionary *)dic
{
    ModelInsurance *insurance = [ModelInsurance new];
    [insurance reflectDataFromOtherObject:dic];
    return insurance;
}
+(BOOL)checkOverTime:(NSString *)beginDate andEndDate:(NSString *)endDate
{
    ModelInsurance *insurance = [UserInsuranceManager sharedManager].userInsurance;
    
    if (!insurance)
    {
        return NO;
    }
    else
    {
        if (beginDate.length>=10&&endDate.length>=10) {
            NSDateFormatter *inFormat = [[NSDateFormatter alloc]init];
            NSTimeZone *tz = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
            [inFormat setTimeZone:tz];
            
            
            [inFormat setDateFormat:@"yyyy-MM-dd"];
            NSDate *tarBeginDate = [inFormat dateFromString:[beginDate substringToIndex:10]];
            NSDate *tarEndDate = [inFormat dateFromString:[endDate substringToIndex:10]];
            
            if (insurance.beginDate&&insurance.endDate)
            {
                NSTimeInterval beginTime=[tarBeginDate timeIntervalSinceDate:insurance.beginDate];
                NSTimeInterval endTime=[insurance.endDate timeIntervalSinceDate:tarEndDate];
                
                if (beginTime>=0&&endTime>=0) {
                    return YES;
                }else
                {
                    return NO;
                }
                
            }else
            {
                NSDate *inBeginDate = [inFormat dateFromString:insurance.periodStart];
                NSDate *inEndDate = [inFormat dateFromString:insurance.periodEnd];
                
                NSTimeInterval beginTime=[tarBeginDate timeIntervalSinceDate:inBeginDate];
                NSTimeInterval endTime=[inEndDate timeIntervalSinceDate:tarEndDate];
                
                if (beginTime>=0&&endTime>=0) {
                    return YES;
                }else
                {
                    return NO;
                }
                
            }
            
        }else
        {
            return NO;
        }

    }
    
    
    
    
    
    
   
    
    
    
}
@end
